/**
 *  @file SDLAudioManager.h
 *
 *  @date 3-dec-2009
 *  @author Ives van der Flaas
 */

#ifndef SDLAUDIOMANAGER_H_
#define SDLAUDIOMANAGER_H_

#include <string>
#include <map>
#include <tr1/memory>
#include <SDL.h>
#include <SDL_mixer.h>

namespace si_sdl
{

typedef int SoundID;
enum RepeatStyle { PLAYONCE = 0, REPEAT = -1 };

/**
 * Singleton class used to play sounds
 */
class SDLAudioManager
{
public:
	static SDLAudioManager& get()
	{
		static SDLAudioManager mgr;
		return mgr;
	}

	/**
	 * Start a music file (mp3, ogg, ...)
	 * @param location
	 * @param style
	 */
	void startMusic(std::string location, RepeatStyle style);

	/**
	 * Stops the music that's currently playing
	 */
	void stopMusic();

	/**
	 * Plays sound at location, wav only!
	 * @param location
	 * @param style
	 */
	void playSound(std::string location, RepeatStyle style);

	/**
	 * You can't stop sounds. Sorry. This function does not function.
	 * @param sound
	 */
	void stopSound(SoundID sound);
	virtual ~SDLAudioManager();


	/**
	 * If called, the audiomgr is silent until "beLoud" is called
	 */
	void beSilent();

	/**
	 * If called, the audiomgr is un-muted. It'll make noise.
	 */
	void beLoud();
private:
	SDLAudioManager();

	std::map<int, std::tr1::shared_ptr<Mix_Chunk> > fCurrentSounds;
	std::tr1::shared_ptr<Mix_Music> fMusic;

	bool fMuted;
};

}

#endif /* SDLAUDIOMANAGER_H_ */
